<?php

header('Content-Type:application/json; charset=utf-8'); #返回json
session_start();

if(empty($_SESSION['userinfo'])){
    //未登录，引导登录
    $result = [
        'code' => '-1',
        'msg' => '未登录，请登录',
    ];
    echo json_encode($result);
    exit ;

}



$stu_id=  $_GET["stu_id"]??-1;
$cou_id=  $_GET["cou_id"]??'';

        
try {
    $dbh = new PDO("mysql:host=127.0.0.1;dbname=g09short", 'root', 'G09short.'); //初始化一个PDO对象
    $sql = "SELECT S.sub_id, W.work_id, S.stu_creatime, S.sub_score,W.work_title, W.work_startime, W.work_endtime, W.cou_id 
    FROM (SELECT * FROM zyh_submit WHERE stu_id = " . $stu_id . ") S RIGHT JOIN 
    (SELECT * FROM zyh_work WHERE cou_id = '" . $cou_id . "') W
    ON S.work_id = W.work_id";
    $stmt = $dbh->query($sql,    PDO::FETCH_ASSOC);
    $dbh=null;
    if ($stmt -> rowCount() == 0){
        $data['workTable'] = null;
    }
    else{
        $data['workTable'] = $stmt->fetchAll();
    }

} catch (PDOException $e) {
    
    $res=  [
        'code' => '5',
        'msg' => '出错',
    ];
}


$res=  [
    'code' => '0',
    'msg' => '获取数据成功',
    'data' => $data,
];
//返回json
echo json_encode($res);
